1
|
|
|
import React, { Component, Fragment } from "react" |
2
|
|
|
import { graphql, StaticQuery } from "gatsby" |
3
|
|
|
import "./matches-overview.scss" |
4
|
|
|
import MatchWithLogo from "./match-with-logo" |
5
|
|
|
|
6
|
|
|
class MatchesOverviewDetails extends Component { |
7
|
|
|
constructor(props) { |
8
|
|
|
super(props) |
9
|
|
|
|
10
|
|
|
this.state = { |
11
|
|
|
data: [], |
12
|
|
|
loading: true, |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
this.apiServerUrl = props.config.site.siteMetadata.serverUrl |
16
|
|
|
this.apiLogoUrl = props.config.site.siteMetadata.logoUrl |
17
|
|
|
this.apiRefreshRate = props.config.site.siteMetadata.refreshRate |
18
|
|
|
this.timeout = {} |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
updateData() { |
22
|
|
|
const { season, regnumber, previous = false } = this.props |
23
|
|
|
let apiUrl = `${this.apiServerUrl}/seasons/${season}/matches/upcoming/${regnumber}` |
24
|
|
|
|
25
|
|
|
if (previous) { |
26
|
|
|
apiUrl = `${this.apiServerUrl}/seasons/${season}/matches/previous/${regnumber}` |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
fetch(apiUrl) |
30
|
|
|
.then((response) => response.json()) |
31
|
|
|
.then((json) => this.setState({ data: json, loading: false })) |
32
|
|
|
|
33
|
|
|
this.timeout = setTimeout(() => { |
34
|
|
|
this.updateData(() => {}) |
35
|
|
|
}, this.apiRefreshRate) |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
componentDidMount() { |
39
|
|
|
this.updateData() |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
componentWillUnmount() { |
43
|
|
|
clearInterval(this.timeout) |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
render() { |
47
|
|
|
if (this.state.loading === false && this.state.data) { |
48
|
|
|
this.state.data.sort( |
49
|
|
|
(a, b) => a.dateTime - b.dateTime || a.division - b.division |
50
|
|
|
) |
51
|
|
|
|
52
|
|
|
if (this.state.data.length <= 0) { |
53
|
|
|
return ( |
54
|
|
|
<div className="matches_overview__wrapper"> |
55
|
|
|
Geen wedstrijden gevonden. |
56
|
|
|
</div> |
57
|
|
|
) |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
const ignore = this.props.exclude || [] |
61
|
|
|
|
62
|
|
|
return ( |
63
|
|
|
<div className="matches_overview__wrapper matches_overview__wrapper--details"> |
64
|
|
|
{this.state.data.map((match, i) => { |
65
|
|
|
if (ignore.includes(match.division)) { |
66
|
|
|
return <Fragment key={i} /> |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return <MatchWithLogo match={match} lazyload={false} /> |
70
|
|
|
})} |
71
|
|
|
</div> |
72
|
|
|
) |
73
|
|
|
} else { |
74
|
|
|
return <div>Loading...</div> |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
const query = graphql` |
80
|
|
|
query { |
81
|
|
|
site { |
82
|
|
|
siteMetadata { |
83
|
|
|
serverUrl |
84
|
|
|
refreshRate |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
` |
89
|
|
|
|
90
|
|
|
export default ({ season, regnumber, exclude, previous }) => ( |
91
|
|
|
<StaticQuery |
92
|
|
|
query={query} |
93
|
|
|
render={(data) => ( |
94
|
|
|
<MatchesOverviewDetails |
95
|
|
|
config={data} |
96
|
|
|
season={season} |
97
|
|
|
regnumber={regnumber} |
98
|
|
|
exclude={exclude} |
99
|
|
|
previous={previous} |
100
|
|
|
/> |
101
|
|
|
)} |
102
|
|
|
/> |
103
|
|
|
) |
104
|
|
|
|